"""
文件名: OrderInterface.py
作用: 封装订单相关接口
作者: 健哥
"""

from Untils.SendMethod import SendMethod
from Interface.MemberInterface import MemberInterface


class OrderInterface:
    def __init__(self):
        self.url = 'http://139.159.146.104:8083'
        member = MemberInterface()
        self.headers = member.get_token(username='冰红茶', password='123456')

    def confirm_order(self):
        """
        根据购物车信息确认订单
        :return:
        """
        url = self.url + '/order/generateConfirmOrder'
        return SendMethod.send_method(method='post', url=url, headers=self.headers)

    def generate_order(self, payload):
        """
        生成订单
        :param payload: 生成订单的请求参数
        :return:
        """
        url = self.url + '/order/generateOrder'
        return SendMethod.send_method(method='post', url=url, json=payload, headers=self.headers)

    def pay_success(self, order_id):
        """
        支付回调
        :param order_id: 订单id
        :return:
        """
        url = self.url + '/order/paySuccess'
        payload = {'orderId': order_id}
        return SendMethod.send_method(method='post', url=url, data=payload, headers=self.headers)


if __name__ == '__main__':
    order = OrderInterface()
    # print(order.confirm_order())
    payload = {
        "memberReceiveAddressId": 229,
        "payType": 1
    }
    # print(order.generate_order(payload=payload))
    print(order.pay_success(50))
